/**
 * Created by zhoushg on 2017/9/29.
 */
import getData from './funcs/getData'
import { isEmptyObject, isEmptyStr, isRange } from './funcs/required'
import { toast } from '../utils/gui_main'
import { getToken } from '../utils/auth'
// addCode
// rkFm9rF7H Start

export function UDTtest(data) { // test-修改
  var data = data
  return new Promise(resolve => {
    if (isEmptyStr(data._id)) {
      toast.warn('列表唯一id不能为空')
      resolve(false)
      return
    }
    if (isEmptyStr(data.name)) {
      toast.warn('名称不能为空')
      resolve(false)
      return
    }
    const data2 = {

      _id: data._id, // 列表唯一id
      name: data.name, // 名称
      age: data.age, // 年龄
      key: data.key, // 键
      value: data.value // 值
    }
    data = data2
    data.token = getToken()
    function callBack(data) {
      resolve(data)
    }
    getData({
      url: '/test/update',
      method: 'post',
      data
    }, callBack)
  })
}

// rkFm9rF7H end

// rkvXqHKmH Start

export function ADtest(data) { // test-新增
  var data = data
  return new Promise(resolve => {
    const data2 = {

      name: data.name, // 名称
      age: data.age, // 年龄
      key: data.key, // 键
      value: data.value // 值
    }
    data = data2
    data.token = getToken()
    function callBack(data) {
      resolve(data)
    }
    getData({
      url: '/test/add',
      method: 'post',
      data
    }, callBack)
  })
}

// rkvXqHKmH end
